using System;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Evaluant.Uss.ObjectContext;
using Evaluant.Uss;
using Domain;

namespace NUnit.Mapping.Documentation
{
    [TestClass]
    public class Fixture
    {
        protected ObjectContext oc;
        protected Evaluant.Uss.SqlMapper.SqlMapperProvider provider = new Evaluant.Uss.SqlMapper.SqlMapperProvider();

        public Fixture()
        {
            provider.ConnectionString = "Server=EUSS;DataBase=uss;Integrated Security=true";
            provider.Dialect = "Evaluant.Uss.SqlMapper.MsSqlDialect";
            provider.Driver = "Evaluant.Uss.SqlMapper.MsSqlDriver";
            provider.TablePrefix = "DOC_";
            provider.RegisterMetaData(MetaDataFactory.FromAssembly(typeof(Company).Assembly));

            Configure();

            provider.InitializeConfiguration();

            oc = new ObjectService(provider).CreateObjectContext();
        }

        public virtual void Configure()
        {
            provider.MappingFileName = @"..\..\..\NUnit\Mapping\Documentation\mapping.xml";
        }

        [TestMethod]
        public void ShouldSerializeInheritedEntities()
        {
            oc.InitializeRepository();

            Factory f = new Factory();
            f.Name = "Wrigley";
            f.City = "Whashington";
            f.SiretNb = 1;

            oc.BeginTransaction();
            oc.Serialize(f);
            oc.CommitTransaction();

            oc.Clear();

            IList<Company> cies = oc.Load<Company>();
            Assert.AreEqual(1, cies.Count);
            Assert.AreEqual("Wrigley", cies[0].Name);

        }

    }
}